<?php
namespace App\Models;

use Illuminate\Database\Eloquent\Model;

class ActivityCoupon extends Model
{

    protected $table = 'activity_coupon';

    public $timestamps = false;


    /**
     * @param int $activity_id
     * @param array $coupon
     * @return bool
     */
    public function setData(int $activity_id, array $coupon)
    {

        $re_del = $this->where('activity_id', $activity_id)->delete();
        $coupon = array_filter($coupon);
        if($coupon) {
            $insert_data = [];
            foreach ($coupon as $coupon_id) {
                $insert_data[] = [
                    'activity_id' => $activity_id,
                    'coupon_id' => $coupon_id,
                ];
            }
            $re_insert = $this->insert($insert_data);
        }
        return true;

    }

}
